package cn.com.b2office.dao.hibernate;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.com.b2office.dao.ExDataDao;
import cn.com.b2office.domain.ExData;

public class ExDataDaoHibernateImpl extends HibernateDaoSupport implements
		ExDataDao {

	public int addExData(ExData data) {
		return (Integer) getHibernateTemplate().save(data);
	}

	public Serializable create(Object o) {
		return getHibernateTemplate().save(o);
	}

	public void delete(Object o) {
		getHibernateTemplate().delete(o);
	}

	@SuppressWarnings("unchecked")
	public List<ExData> listExData(int size) {
		List<ExData> list = null;
		Session s = getSession();
		try {
			list = s.createQuery("from ExData order by modifytime asc").list();
		} catch (RuntimeException e) {
			throw e;
		} finally {
			releaseSession(s);
		}
		return list;
	}

	public Object read(Class clasz, Serializable id) {
		return getHibernateTemplate().get(clasz, id);
	}

	public void update(Object o) {
		getHibernateTemplate().update(o);
	}

	public void delete(Class clasz, Serializable id) {
		Session s = getSession();
		try {
			Object o = s.get(clasz, id);
			if (o != null) {
				s.delete(o);
				s.flush();
			}
		} catch (RuntimeException e) {
			throw e;
		} finally {
			releaseSession(s);
		}
	}

	public void saveOrUpdate(Object o) {
		getHibernateTemplate().saveOrUpdate(o);
	}

}
